const Router = require('koa-router')
const Order = require('../moudel/Order')
const rt = new Router()

// 提交预订单
rt.post('/addorder' , async(ctx)=>{
    const order = ctx.request.body
    let results = await Order.addOrder(order)
    if(results.affectedRows == 1){
        ctx.body = {code:'200',msg:'成功'}
    }else{
        ctx.body = {code:'201',msg:'订单异常!'}
    }
})
// 修改订单
rt.put('/uporder/:oid', async(ctx)=>{
    const oid = ctx.params.oid
    let result = await Order.payOrder(oid)
    if(result.affectedRows == 1){
        ctx.body = {code:'200',msg:'支付成功!'}
    }else{
        ctx.body = {code:'201',msg:'订单异常!'}
    }
    // console.log(oid);
})


module.exports = rt